Type: concept
Confidence: 0.85
Created: 2026-04-16
Updated: 2026-04-16
Tags: UrhoX2D图形动画LuaAPI游戏开发

UrhoX 2D动画系统API

概述

UrhoX 2D动画系统基于 AnimationSet2D 资源和 AnimatedSprite2D 组件,支持帧动画播放与循环模式控制,另有 StretchableSprite2D 支持九宫格拉伸。

关键内容

类层次

AnimationSet2D

local animSet = cache:GetResource("AnimationSet2D", "Sprites/hero.scml")
-- 查询动画数量和名称
local count = animSet.numAnimations       -- readonly
local name  = animSet:GetAnimation(0)    -- 按索引获取动画名(Lua 0-based 调用)

AnimatedSprite2D 关键属性

属性 类型 说明
animationSet AnimationSet2D* 关联动画集资源
entity String Spriter 实体名(多实体 scml 时使用)
animation String 当前播放的动画名
loopMode LoopMode2D 循环模式(LM_DEFAULT / LM_FORCE_LOOPED / LM_FORCE_CLAMPED)
speed float 播放速度倍率(1.0=正常)

播放动画

local animSprite = node:CreateComponent("AnimatedSprite2D")
animSprite.animationSet = cache:GetResource("AnimationSet2D", "Sprites/hero.scml")
animSprite.entity = "hero"
animSprite:SetAnimation("run", LM_DEFAULT)
animSprite.speed = 1.5

StretchableSprite2D

九宫格拉伸精灵,适合按钮背景、对话框等 UI 元素。

local stretchable = node:CreateComponent("StretchableSprite2D")
stretchable.sprite = cache:GetResource("Sprite2D", "UI/button.png")
-- border 定义九宫格边缘(left, top, right, bottom 像素数)
stretchable.border = IntRect(8, 8, 8, 8)

来源

相关